package com.cts.learninglibrary.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cts.learninglibrary.mapper.UserMapper;
import com.cts.learninglibrary.pojo.User;
import com.cts.learninglibrary.service.UserService;
import com.cts.learninglibrary.util.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author arctique
 * @date 2020/8/11 15:46
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 查找全部用户信息
     *
     * @return R
     */
    @Override
    public R findAll() {
        List<User> userList = userMapper.findAll();
        return R.ok(userList);
    }

    /**
     * 通过用户名查找用户信息
     *
     * @param username
     * @return User
     */
    @Override
    public User findByUsername(String username) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return baseMapper.selectOne(queryWrapper);
    }
}
